# (C) Copyright 2020-2023 Intel Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
"""Unit tests"""

import os

TEST_SRC = ['test_gurt.c', 'test_gurt_telem_producer.c']


def scons():
    """Scons function"""
    if GetOption('help'):
        return

    Import('env', 'gurt_targets')

    test_env = env.Clone()
    test_env.require('mercury', 'uuid')
    test_env.AppendUnique(LIBS=['pthread', 'cmocka', 'm', 'dl'])
    test_env.AppendUnique(CXXFLAGS=['-std=c++0x'])

    mocks_ld_script = f"{Dir('.').srcnode()}/mocks-gurt-ld-opts"
    test_env.AppendUnique(LINKFLAGS=[f'-Wl,@{mocks_ld_script}'])
    mocks = test_env.SharedObject(['mocks_gurt.c'])
    Export('mocks')

    tests = []
    for test in TEST_SRC:
        testobj = test_env.Object(test)
        testname = os.path.splitext(test)[0]
        testprog = test_env.d_test_program(target=testname,
                                           source=testobj + gurt_targets + [mocks],
                                           LIBS=test_env["LIBS"] + ['yaml'])
        tests.append(testprog)

    Default(tests)


if __name__ == "SCons.Script":
    scons()
